#include "SpriteExDirectDraw.h"

#include "SpriteDirectDraw.h"

namespace YoghurtGum
{

	SpriteExDirectDraw::SpriteExDirectDraw(float a_Delay) : SpriteEx(a_Delay)
	{
		m_TargetSurface = RenderMethodDirectDraw::GetSingleton()->GetBackBuffer();
		m_TargetObject = RenderMethodDirectDraw::GetSingleton()->GetObject();

		m_CenterX = 0;
		m_CenterY = 0;

		SetDelay(a_Delay);
	}

	SpriteExDirectDraw::~SpriteExDirectDraw()
	{

	}

	void SpriteExDirectDraw::SetCenter(int a_X, int a_Y)
	{
		m_CenterX = a_X;
		m_CenterY = a_Y;
	}

	void SpriteExDirectDraw::Scale(float a_RatioX, float a_RatioY)
	{
		m_ScaleX = a_RatioX;
		m_ScaleY = a_RatioY;
	}

	void SpriteExDirectDraw::Rotate(float a_Degrees)
	{
		m_Rotation = a_Degrees;
	}

	void SpriteExDirectDraw::PrevFrame()
	{
		m_Current = (--m_Current < 0) ? m_Current - 1 : m_Current;

		m_Dimensions.left = m_Current * m_SpriteWidth;
		m_Dimensions.right = (m_Current + 1) * m_SpriteWidth;
	}

	void SpriteExDirectDraw::NextFrame()
	{
		m_Current = (++m_Current > m_Total) ? 0 : m_Current;

		m_Dimensions.left = m_Current * m_SpriteWidth;
		m_Dimensions.right = (m_Current + 1) * m_SpriteWidth;
	}

	void SpriteExDirectDraw::Draw(float a_X, float a_Y, int a_Frame /*= -1*/, float a_Depth /*= 0.f*/)
	{
		/*
				YGC* buffer = pixels->GetBuffer();
		YGC* target_buffer = rotated->GetBuffer();

		int height = pixels->GetHeight();
		int width = pixels->GetWidth();
		int pitch = pixels->GetPitch();

		rotation = (rotation > 360.f) ? 0.f : rotation;
		int irot = (int)rotation;

		for (int y = 0; y < height; y++)
		{
			for (int x = 0; x < width; ++x)
			{
				int cx = x - 16;
				int cy = y - 16;

				int dx = (cx * precomp_cos[irot]) - (cy * precomp_sin[irot]) + 16;
				int dy = (cx * precomp_sin[irot]) + (cy * precomp_cos[irot]) + 16;

				if (dx < 0 || dx > 32 || dy < 0 || dy > 32) { continue; }

				target_buffer[x] = buffer[(dy * pitch) + dx];
			}
			
			target_buffer += pitch;
		}

		rotated->CopyTo(m_Lines, 20, 20);
		*/
	}

	Surface* SpriteExDirectDraw::ToSurface( int a_Frame /*= -1*/ )
	{
		return NULL;
	}

}; // namespace YoghurtGum